package com.c2soft.ncmx.exch.config;

import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.spring.ActiveMQConnectionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.jms.core.JmsTemplate;

import com.c2soft.ncmx.exch.jms.JmsSender;
import com.c2soft.ncmx.exch.mains.*;

@Configuration
@PropertySource("classpath:jmsconfigs.properties")
public class JmsConfigForTest {
	
	@Value("${ncmx.exchange.jms.brokerUrl}")
	private String jmsBrokerURL;

	@Bean
	public JmsTemplate jmsTestTemplate() {
		JmsTemplate jmsTemplate = new JmsTemplate();
		jmsTemplate.setConnectionFactory(connectionTestFactory());
		return jmsTemplate;
	}

	@Bean
	public ActiveMQConnectionFactory connectionTestFactory() {
		ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
		System.out.println(jmsBrokerURL);
		activeMQConnectionFactory.setBrokerURL("tcp://dell:61616");
		return activeMQConnectionFactory;
	}
	
	@Bean
	 public JmsSender jmsSender() {
	 JmsSender jmsSender = new JmsSender();
	 jmsTestTemplate().setDefaultDestination(new ActiveMQQueue("ncmx.order.queue"));
	 jmsSender.setJmsTemplate(jmsTestTemplate());
	 return jmsSender;
	 }
	
	@Bean
	public MockOrders mockOrder(){
		return new MockOrders();
	}
}
